package com.lxmes.base.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import com.lxmes.base.domain.JcSupplierItem;
import com.lxmes.base.service.IJcSupplierItemService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;

/**
 * 供应商与物料对应关系Controller
 * 
 * @author 王超
 * @date 2022-08-21
 */
@RestController
@RequestMapping("/base/itemsupper")
public class JcSupplierItemController extends BaseController
{
    @Autowired
    private IJcSupplierItemService jcSupplierItemService;

    /**
     * 查询供应商与物料对应关系列表
     */
   // @PreAuthorize("@ss.hasPermi('base:itemsupper:list')")
    @GetMapping("/list")
    public TableDataInfo list(JcSupplierItem jcSupplierItem)
    {
        startPage();
        List<JcSupplierItem> list = jcSupplierItemService.selectJcSupplierItemList(jcSupplierItem);
        return getDataTable(list);
    }

    /**
     * 导出供应商与物料对应关系列表
     */
    @PreAuthorize("@ss.hasPermi('base:itemsupper:export')")
    @Log(title = "供应商与物料对应关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JcSupplierItem jcSupplierItem)
    {
        List<JcSupplierItem> list = jcSupplierItemService.selectJcSupplierItemList(jcSupplierItem);
        ExcelUtil<JcSupplierItem> util = new ExcelUtil<JcSupplierItem>(JcSupplierItem.class);
        util.exportExcel(response, list, "供应商与物料对应关系数据");
    }

    /**
     * 获取供应商与物料对应关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:itemsupper:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(jcSupplierItemService.selectJcSupplierItemById(id));
    }

    /**
     * 新增供应商与物料对应关系
     */
   // @PreAuthorize("@ss.hasPermi('base:itemsupper:add')")
    @Log(title = "供应商与物料对应关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JcSupplierItem jcSupplierItem)
    {
        return toAjax(jcSupplierItemService.insertJcSupplierItem(jcSupplierItem));
    }

    /**
     * 修改供应商与物料对应关系
     */
   // @PreAuthorize("@ss.hasPermi('base:itemsupper:edit')")
    @Log(title = "供应商与物料对应关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JcSupplierItem jcSupplierItem)
    {
        return toAjax(jcSupplierItemService.updateJcSupplierItem(jcSupplierItem));
    }

    /**
     * 删除供应商与物料对应关系
     */
    @PreAuthorize("@ss.hasPermi('base:itemsupper:remove')")
    @Log(title = "供应商与物料对应关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(jcSupplierItemService.deleteJcSupplierItemByIds(ids));
    }

    @GetMapping("/addItemInfo/{ids}")
    public AjaxResult addItemInfo(@PathVariable Long[] ids)
    {
        List<JcSupplierItem> list = jcSupplierItemService.addItemInfo(ids);
        return AjaxResult.success(list);
    }
}
